if (typeof (LBet) === "undefined") var LBet = {};

LBet.New = function (time, noteNumber, length) {
    var lbet = {};
    lbet.Time = time;
    lbet.NoteNumber = noteNumber;
    lbet.Length = length;

    return lbet;
}

LBet.ParseData = function (data) {
    var noteOnList = [], noteOffList = [];
    var time = 0, event;

    //Tạo 2 mảng
    for (var i = 0; i < data.length; i++) {
        time += data[i][1];
        event = data[i][0].event;

        if (event.subtype == "noteOn") {

            /*noteOnList.push(new {
            Time: time,
            NoteNumer: event.noteNumber,
            Length: 0
            });*/

            noteOnList.push(LBet.New(time, event.noteNumber, 0));
        }

        if (event.subtype == "noteOff") {

            /*noteOnList.push(new {
            Time: time,
            NoteNumer: event.noteNumber
            });*/

            noteOffList.push(LBet.New(time, event.noteNumber, 0));
        }
    }

    for (var i = 0; i < noteOnList.length; i++) {
        for (var j = 0; j < noteOffList.length; j++)
            if (noteOnList[i].NoteNumber == noteOffList[j].NoteNumber) {

                noteOnList[i].Length = noteOffList[j].Time - noteOnList[i].Time;
                noteOffList.splice(j, 1);

                break;
            }
    }

    return noteOnList;
};



